<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <span>欢迎您，{{userName||'游客'}}</span>
      <!-- <Badge :dot="!!messageUnreadCount">
        <Avatar :src="userAvator"/>
      </Badge>-->
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <!-- <DropdownItem name="message">
          消息中心<Badge style="margin-left: 10px" :count="messageUnreadCount"></Badge>
        </DropdownItem>-->
        <DropdownItem name="logout">退出登录</DropdownItem>
        <DropdownItem  ><p @click="changepwd">修改密码</p> </DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import "./user.less";
import { mapActions } from "vuex";
import { getUserName } from "@/libs/util";
export default {
  name: "User",
  props: {
    userAvator: {
      type: String,
      default: ""
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      userName: getUserName()
    };
  },
  methods: {
    ...mapActions(["handleLogOut"]),
    logout() {
      this.handleLogOut().then(() => {
        sessionStorage.setItem("tagNaveList", "");
        this.$router.push({
          name: "login"
        });
      });
    },
    changepwd() {
      this.$router.push({
        name: "changepwd"
      });
    },
    message() {
      this.$router.push({
        name: "message_page"
      });
    },
    handleClick(name) {
      switch (name) {
        case "logout":
          this.logout();
          break;
        case "message":
          this.message();
          break;
      }
    }
  }
};
</script>
